package com.zhangxiaofanfan.hotcode.second;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode078 {
    public static void main(String[] args) {
        HotCode078 hotCode = new HotCode078();
        int[] nums = {3,2,1,0,4};
        System.out.println(hotCode.canJump(nums));
    }

    public boolean canJump(int[] nums) {
        if (nums.length <= 1) {
            return true;
        }
        int maxJumpIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            if (maxJumpIndex < i) {
                return false;
            }
            maxJumpIndex = Math.max(maxJumpIndex, i + nums[i]);
            if (maxJumpIndex >= nums.length - 1) {
                return true;
            }
        }
        return true;
    }
}
